﻿CREATE PROC spObtenCampos
	@pnIdLaboratorio    INT,
	@pnIdEstudio		INT,
	@pnIdCampo			INT,
	@psNombreCampo		VARCHAR(100)
AS
BEGIN
	SET NOCOUNT ON
	
	IF @psNombreCampo = ''    
		SET @psNombreCampo = NULL; 
  
	SELECT	c.IdEstudio ,
	        c.IdLaboratorio ,
	        c.IdCampo ,
	        c.NombreCampo ,
	        c.IdTipoCampo ,
	        tc.Descripcion AS NombreTipoCampo,
	        c.EsRequerido ,
	        c.Unidad ,
	        c.Orden
	FROM	dbo.CatCampoEstudio	c
	INNER JOIN dbo.CatTipoCampo	tc
	ON		c.IdTipoCampo	= tc.IdTipoCampo
	WHERE	(c.NombreCampo	LIKE '%' + @psNombreCampo + '%' OR @psNombreCampo IS NULL)
	AND		(c.IdCampo		= @pnIdCampo OR @pnIdCampo IS NULL)  
	AND		c.IdLaboratorio = @pnIdLaboratorio
	AND		c.IdEstudio		= @pnIdEstudio
	
	SET NOCOUNT OFF
END
GO